﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iLangl.Model;

namespace iLangl.LanguageWire.DAL.LanguageWireDAL.MockupStorage
{
	public class MockupCompanyDAL : MockupBaseDAL, ICompanyDAL
	{
		public int GetLWCompanyId(Guid companyId)
		{
			foreach (dtoMockupStorage.CompanyRow cr in Storage.Company)
			{
				if (cr.Id == companyId)
				{
					return cr.TPIdentity;
				}
			}

			return -1;
		}


		public void CreateCompany(Company company)
		{
			Guid companyId = new Guid(company.Id);
			int referenceNumber = GetLWCompanyId(companyId);
			company.TPIdentity = referenceNumber.ToString();

			if (referenceNumber > 0)
			{
				return;
			}

			dtoMockupStorage.CompanyRow companyRow = Storage.Company.NewCompanyRow();

			companyRow.Id = new Guid(company.Id);

			if (!string.IsNullOrEmpty(company.Name))
				companyRow.Name = company.Name;

			if (!string.IsNullOrEmpty(company.Address))
				companyRow.Address = company.Address;

			if (!string.IsNullOrEmpty(company.City))
				companyRow.City = company.City;

			if (!string.IsNullOrEmpty(company.Country))
				companyRow.Country = company.Country;

			if (!string.IsNullOrEmpty(company.Currency))
				companyRow.Currency = company.Currency;

			if (!string.IsNullOrEmpty(company.Phone))
				companyRow.Phone = company.Phone;

			if (!string.IsNullOrEmpty(company.State))
				companyRow.State = company.State;

			if (!string.IsNullOrEmpty(company.Zip))
				companyRow.Zip = company.Zip;

			Storage.Company.AddCompanyRow(companyRow);

			AcceptChanges();
			iLangl.LanguageWire.DAL.iLanglDAL.DALFacade.Instance.CompanyDAL.UpdateCompanyReference(company.Id, companyRow.TPIdentity, null);
		}

		public Model.Company GetLWCompanyInfo()
		{
			return new iLangl.LanguageWire.DAL.LanguageWireDAL.RealStorage.CompanyDAL().GetLWCompanyInfo();
		}
	}
}
